﻿using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Threading.Tasks;

namespace Com.JunCaiSoft.Common.AssistClass
{
    public class RSAKeyExtension
    {
        public static RSAParameters GenerateKey()
        {
            using (var key = new RSACryptoServiceProvider(2048))
            {
                return key.ExportParameters(true);
            }
        }

        public class TokenAuthOption
        {
            public static string Audience { get; } = "RSAAudience";
            public static string Issuer { get; } = "RSAIssuer";
            public static RsaSecurityKey Key { get; } = new RsaSecurityKey(RSAKeyExtension.GenerateKey());
            public static SigningCredentials SigningCredentials { get; } = new SigningCredentials(Key, SecurityAlgorithms.RsaSha256Signature);
            public static TimeSpan ExpiresSpan { get; } = TimeSpan.FromMinutes(20);
        }
    }
}
